// https://umijs.org/config/
import { defineConfig, utils } from 'umi';
import myTheme from '../src/theme/myTheme';
import proxy from './proxy';
import webpackPlugin from './plugin.config';
const { winPath } = utils; // preview.pro.ant.design only do not use in your production ;
// preview.pro.ant.design 专用环境变量，请不要在你的项目中使用它。
import routes from './routes';
const { ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION, REACT_APP_ENV, GA_KEY } = process.env;

const RouteWatcher = '@/components/PageTab/RouteWatcher';

export default defineConfig({
  hash: true,
  antd: {},
  analytics: GA_KEY
    ? {
        ga: GA_KEY,
      }
    : false,
  dva: {
    hmr: true,
  },
  locale: {
    // default zh-CN
    default: 'zh-CN',
    // default true, when it is true, will use `navigator.language` overwrite default
    antd: true,
    baseNavigator: true,
  },
  dynamicImport: {
    loading: '@/components/PageLoading/index',
  },
  targets: {
    ie: 11,
  },
  //配置项目名称
  base: '/fsms' , 
  publicPath: '/public/' ,
  routes,
  // umi routes: https://umijs.org/docs/routing
  // routes: [
  //   {
  //     path: '/',
  //     component: '../layouts/BlankLayout',
  //     routes: [
  //       {
  //         path: '/user',
  //         component: '../layouts/UserLayout',
  //         routes: [
  //           {
  //             path: '/user',
  //             redirect: '/user/login',
  //           },
  //         ],
  //       },
  //       {
  //         path: '/screen',
  //         component: './screen',
  //       },
  //       {
  //         path: '/',
  //         component: '../layouts/BasicLayout',
  //         Routes: ['src/pages/Authorized'],
  //         authority: ['admin', 'user'],
  //         routes: [
  //           {
  //             path: '/overview',
  //             name: '项目总览',
  //             icon: 'dashboard',
  //             component: './overview',
  //             wrappers: [RouteWatcher],
            
  //           },
            
  //            {
  //             path: '/monitoring',
  //             icon: 'table',
  //             name: '实时监控',
  //             routes: [
  //               {
  //                 path: '/monitoring/realtime',
  //               //  name: '实时数据',
  //                 component: './monitoring/realtime',
  //                 wrappers: [RouteWatcher],
  //               },
  //               {
  //                 name: '配电图',
  //                 path: '/monitoring/distributionDiagram',
  //                 component: './monitoring/distributionDiagram',
  //                 wrappers: [RouteWatcher],
  //               },
  //               {
  //                 name: '设备类名A',
  //                 path: '/monitoring/deviceNameA',
  //                 component: './monitoring/deviceNameA',
                
  //                 wrappers: [RouteWatcher],
  //               },
               
  //               {
  //                 name: '设备类名B',
  //                 path: '/monitoring/deviceNameB',
  //                 component: './monitoring/deviceNameB',
  //                 wrappers: [RouteWatcher],
  //               },
  //               {
  //                 name: '设备类名C',
  //                 path: '/monitoring/deviceNameC',
  //                 component: './monitoring/deviceNameC',
  //                 wrappers: [RouteWatcher],
  //               }
  //             ],
  //           },
  //           {
  //             path: '/energyAnalysis',
  //             icon: 'table',
  //             name: '能耗分析',
  //             routes: [
  //               {
  //                 path: '/energyAnalysis/survey',
  //                 name: '能耗概况',
  //                 component: './energyAnalysis/survey',
  //                 wrappers: [RouteWatcher],
  //               },
  //               {
  //                 name: '同比分析',
  //                 path: '/energyAnalysis/sameAnalysis',
  //                 component: './energyAnalysis/sameAnalysis',
  //                 wrappers: [RouteWatcher],
  //               },
  //               {
  //                 path: '/energyAnalysis/chainAnalysis',
  //                 name: '环比分析',
  //                 component: './energyAnalysis/chainAnalysis',
  //                 wrappers: [RouteWatcher],
  //               },
  //               {
  //                 name: '能耗报表',
  //                 path: '/energyAnalysis/report',
  //                 component: './energyAnalysis/report',
  //                 wrappers: [RouteWatcher],
  //               },
  //               {
  //                 name: '复费率报表',
  //                 path: '/energyAnalysis/multipleRateReport',
  //                 component: './energyAnalysis/multipleRateReport',
  //                 wrappers: [RouteWatcher],
  //               },
  //               {
  //                 name: '电能报表',
  //                 path: '/energyAnalysis/electricEnergyReport',
  //                 component: './energyAnalysis/electricEnergyReport',
  //                 wrappers: [RouteWatcher],
  //               }
                
  //             ],
  //           },
           
  //           {
  //             path: '/monitoringAnalysis',
  //             icon: 'table',
  //             name: '监测分析',
  //             routes: [
  //               {
  //                 path: '/monitoringAnalysis/harmonicMonitoring',
  //                 name: '谐波监测',
  //                 component: './monitoringAnalysis/harmonicMonitoring',
  //                 wrappers: [RouteWatcher],
  //               },
  //               {
  //                 name: '三相不平衡度',
                
  //                 path: '/monitoringAnalysis/threePhaseUnbalance',
  //                 component: './monitoringAnalysis/threePhaseUnbalance',
  //                 wrappers: [RouteWatcher],
  //               }, {
  //                 path: '/monitoringAnalysis/maximumReport',
  //                 name: '最大需量报表',
  //                 component: './monitoringAnalysis/maximumReport',
  //                 wrappers: [RouteWatcher],
  //               },
  //               {
  //                 name: '需量监测',
  //                 path: '/monitoringAnalysis/monitoring',
  //                 component: './monitoringAnalysis/monitoring',
  //                 wrappers: [RouteWatcher],
  //               }
  //             ],
  //           },
  //           {
  //             path: '/reportAnalysis',
  //             icon: 'table',
  //             name: '报告分析',
  //             routes: [
             
  //               {
  //                 name: '用户报告',
  //                 path: '/reportAnalysis/user',
  //                 component: './reportAnalysis/user',
  //                 wrappers: [RouteWatcher],
  //               }, {
  //                 path: '/reportAnalysis/powerConsumption',
  //                 name: '用电报告',
  //                 component: './reportAnalysis/powerConsumption',
  //                 wrappers: [RouteWatcher],
  //               },
  //               {
  //                 name: '报告文件',
  //                 path: '/reportAnalysis/reportDocument',
  //                 component: './reportAnalysis/reportDocument',
  //                 wrappers: [RouteWatcher],
  //               }
  //             ],
  //           },
            
  //           {
  //             path: '/alarmManagement',
  //             icon: 'table',
  //             name: '报警管理',
  //             routes: [
             
  //               {
  //                 name: '实时报警',
  //                 path: '/alarmManagement/realTime',
  //                 component: './alarmManagement/realTime',
  //                 wrappers: [RouteWatcher],
  //               }, {
  //                 path: '/alarmManagement/history',
  //                 name: '历史报警',
  //                 component: './alarmManagement/history',
  //                 wrappers: [RouteWatcher],
  //               },
  //               {
  //                 name: '报警总览',
  //                 path: '/alarmManagement/overview',
  //                 component: './alarmManagement/overview',
  //                 wrappers: [RouteWatcher],
  //               }
  //             ],
  //           },
            
  //           {
  //             path: '/mochaITOM',
  //             icon: 'table',
  //             name: '运维管理',
  //             routes: [
              
  //               {
  //                 name: '巡检记录',
  //                 path: '/mochaITOM/patrolRecord',
  //                 component: './mochaITOM/patrolRecord',
  //                 wrappers: [RouteWatcher],
  //               }, {
  //                 path: '/mochaITOM/defectRecord',
  //                 name: '缺陷记录',
  //                 component: './mochaITOM/defectRecord',
  //                 wrappers: [RouteWatcher],
  //               },
  //               {
  //                 name: '培训记录',
  //                 path: '/mochaITOM/trainingRecords',
  //                 component: './mochaITOM/trainingRecords',
  //                 wrappers: [RouteWatcher],
  //               }
  //             ],
  //           },   {
  //             path: '/linkageManagement',
  //             icon: 'table',
  //             name: '联动管理',
  //             routes: [
              
  //               {
  //                 name: '联动条件',
  //                 path: '/linkageManagement/conditions',
  //                 component: './linkageManagement/conditions',
  //                 wrappers: [RouteWatcher],
  //               }, {
  //                 path: '/linkageManagement/result',
  //                 name: '联动结果',
  //                 component: './linkageManagement/result',
  //                 wrappers: [RouteWatcher],
  //               },
  //               {
  //                 name: '联动配置',
  //                 path: '/linkageManagement/configure',
  //                 component: './linkageManagement/configure',
  //                 wrappers: [RouteWatcher],
  //               }
  //             ],
  //           }, 
            
  //           {
  //             path: '/deviceManagement',
  //             icon: 'table',
  //             name: '设备管理',
  //             routes: [
              
  //               {
  //                 name: '设备定义',
  //                 path: '/deviceManagement/definition',
  //                 component: './deviceManagement/definition',
  //                 wrappers: [RouteWatcher],
  //               }, {
  //                 path: '/deviceManagement/list',
  //                 name: '设备列表',
  //                 component: './deviceManagement/list',
  //                 wrappers: [RouteWatcher],
  //               }
  //             ],
  //           }, 
            
  //           {
  //             path: '/authorityManagement',
  //             icon: 'table',
  //             name: '系统管理',
  //             routes: [
  //               {
  //                 path: '/authorityManagement/department',
  //                 name: '部门管理',
  //                 wrappers: [RouteWatcher],
  //                 routes: [
  //                   {
  //                     path: '/authorityManagement/department/configure',
  //                     name: '部门配置',
  //                     component: './authorityManagement/department/configure',
  //                     wrappers: [RouteWatcher],
  //                   }, {
  //                     path: '/authorityManagement/department/info',
  //                     name: '部门页面',
  //                     component: './authorityManagement/department/info',
  //                     wrappers: [RouteWatcher],
  //                   }, {
  //                     path: '/authorityManagement/department/equipment',
  //                     name: '部门设备',
  //                     component: './authorityManagement/department/equipment',
  //                     wrappers: [RouteWatcher],
  //                   }]
  //               },
  //               {
  //                 name: '用户配置',
                  
  //                 path: '/authorityManagement/personnel',
                
  //                 wrappers: [RouteWatcher], routes: [
  //                   {
  //                     path: '/authorityManagement/personnel/edit',
  //                     name: '用户编辑',
  //                     component: './authorityManagement/personnel/edit',
  //                     wrappers: [RouteWatcher],
  //                   }, {
  //                     path: '/authorityManagement/personnel/jurisdiction',
  //                     name: '权限管理',
  //                     component: './authorityManagement/personnel/jurisdiction',
  //                     wrappers: [RouteWatcher],
  //                   }]
  //               }, 
  //               // {
  //               //   path: '/authorityManagement/role',
  //               //   name: '角色管理',
  //               //   icon: 'smile',
  //               //   component: './authorityManagement/role',
  //               //   wrappers: [RouteWatcher],
  //               // },
  //               // {
  //               //   name: '模块管理',
  //               //   icon: 'smile',
  //               //   path: '/authorityManagement/module',
  //               //   component: './authorityManagement/module',
  //               //   wrappers: [RouteWatcher],
  //               // },  
                
  //               {
  //                 name: '系统日志',
                 
  //                 path: '/authorityManagement/log',
  //                 component: './authorityManagement/log',
  //                 wrappers: [RouteWatcher],
  //               }
  //             ],
  //           },
  //           {
  //             path: '/',
  //             redirect: '/overview',
  //           },
  //           {
  //             component: '404',
  //           },
  //         ],
  //       },
  //     ],
  //   },
  // ],
  // Theme for antd: https://ant.design/docs/react/customize-theme-cn
  theme: myTheme,
  define: {
    REACT_APP_ENV: REACT_APP_ENV || false,
    ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION:
      ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION || '', // preview.pro.ant.design only do not use in your production ; preview.pro.ant.design 专用环境变量，请不要在你的项目中使用它。
  },
  ignoreMomentLocale: true,
  lessLoader: {
    javascriptEnabled: true,
  },

  cssLoader: {
    modules: {
      getLocalIdent: (
        context: {
          resourcePath: string;
        },
        _: string,
        localName: string,
      ) => {
        if (
          context.resourcePath.includes('node_modules') ||
          context.resourcePath.includes('ant.design.pro.less') ||
          context.resourcePath.includes('global.less')
        ) {
          return localName;
        }

        const match = context.resourcePath.match(/src(.*)/);

        if (match && match[1]) {
          const antdProPath = match[1].replace('.less', '');
          const arr = winPath(antdProPath)
            .split('/')
            .map((a: string) => a.replace(/([A-Z])/g, '-$1'))
            .map((a: string) => a.toLowerCase());
          return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
        }

        return localName;
      },
    },
  },
  title: false,
  manifest: {
    basePath: '/',
  },
  proxy: proxy[REACT_APP_ENV || 'dev'],
  chainWebpack: webpackPlugin,
  
});
